package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;

    @PostMapping("/plan")
    public ResponseResult save(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.save(nursingPlanDto);
        return success();
    }

    @GetMapping("/plan")
    public ResponseResult<NursingPlanVo> findAll(){
        List<NursingPlanVo> list = nursingPlanService.findAll();
        return success(list);
    }

    @GetMapping("/plan/search")
    public ResponseResult<NursingPlanVo> findByPage(
            @RequestParam(name = "name",required = false)String name,
            @RequestParam(name = "status",required = false)Integer status,
            @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
            @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize
            ){
            PageResponse<NursingPlanVo> list = nursingPlanService.findByPage(name,status,pageNum,pageSize);
            return success(list);
    }

    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> findById(
            @PathVariable(name = "id")Integer id
            ){
            NursingPlanVo nursingPlanVo = nursingPlanService.findById(id);
            return success(nursingPlanVo);
    }

    @DeleteMapping("/plan/{id}")
    public ResponseResult delete(@PathVariable(name = "id")Integer id){
        nursingPlanService.delete(id);
        return success();
    }

    @PutMapping("/plan/{id}")
    public ResponseResult update(
            @PathVariable(name = "id")Integer id,
            @RequestBody NursingPlanDto nursingPlanDto
        ){
        nursingPlanService.update(nursingPlanDto,id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @PathVariable(name = "id")Integer id,
            @PathVariable(name = "status")Integer status
    ){
        nursingPlanService.updateStatus(id,status);
        return success();
    }

}